package org.linlinjava.litemall.admin.job;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.linlinjava.litemall.db.domain.LitemallUserMember;
import org.linlinjava.litemall.db.service.LitemallUserMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @author Administrator
 */
@Component
public class MemberExpireJob {
    private final Log logger = LogFactory.getLog(MemberExpireJob.class);

    @Autowired
    private LitemallUserMemberService userMemberService;

    @Scheduled(fixedDelay = 60 * 60 * 1000)
    public void checkMemberExpire() {
        logger.info("系统开启任务：检查会员是否已经过期");
        List<LitemallUserMember> activeList = userMemberService.findActiveList();
        activeList.forEach(userMember -> {
            if (userMember.getExpirationTime().isBefore(LocalDateTime.now())) {
                userMember.setEffective("0");
                userMember.setDeleted(true);
                userMemberService.updateById(userMember);
            }
        });
        logger.info("系统结束任务：检查会员是否已经过期");
    }




}
